package vn.edu.uit.hotelbooking.JsonParse;

import java.util.ArrayList;

import org.json.JSONArray;

import vn.edu.uit.hotelbooking.model.Province;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class ProvinceParser {
    private static final String LOG_TAG= "ProvinceParser";
    private static Gson gson = new Gson();
    
    /**
     * The method to get a province arraylist from JSON object
     * @param jObject the JSON object
     * @return If success, return a province arraylist. If fail, return null.
     */
    public static ArrayList<Province> getProvinceFromJson (JSONArray jArray) {
        ArrayList<Province> arrlistProvince = new ArrayList<Province>();
        try {
             arrlistProvince = gson.fromJson(jArray.toString(), new TypeToken<ArrayList<Province>>(){}.getType());
             return arrlistProvince;
        } catch (Exception e) {
            // TODO: handle exception
            Log.e(LOG_TAG, e.getMessage());
        }
        return null;
    }    
}
